package cn.pzx.base_module

import android.app.Application
import android.content.Context
import androidx.multidex.MultiDex
import cn.pzx.base_module.interfaces.IComponentApplication

/**
 * @author pzx
 * @description:
 * @date :3/3/21 11:07 AM
 */
open class BaseApp : Application() {

    private val MODULESLIST = arrayOf("cn.pzx.main_module.Main_App")


    override fun attachBaseContext(base: Context?) {
        super.attachBaseContext(base)

        MultiDex.install(base);


    }

    override fun onCreate() {
        super.onCreate()

        moduleApplicationInit(this);
    }

    /**
     * 初始化module 的application
     */
    private fun moduleApplicationInit(baseApplication: BaseApp) {
        for (moduleImpl in MODULESLIST) {
            try {
                val clazz = Class.forName(moduleImpl)
                val obj = clazz.newInstance()
                if (obj is IComponentApplication) {
                    obj.initApp(baseApplication)
                }
            } catch (e: ClassNotFoundException) {
                e.printStackTrace()
            } catch (e: IllegalAccessException) {
                e.printStackTrace()
            } catch (e: InstantiationException) {
                e.printStackTrace()
            }

        }


    }


}